﻿@model CloudStorageLight.Core.BlobDirectoryBase
@{
    Layout = null;
    var idx = 0;
}
<div style="height:100%;width:100%;">
    @using (Ajax.BeginForm("UpdateBlobItem", "Helper", new AjaxOptions { HttpMethod = "post" }, new { id = "blobItemDetailForm" }))
    {
        <div style="width:100%;height:360px;overflow:auto;">
            <table style="width:100%;">
                <tr>
                    <th>@CloudStorageLight.SampleWeb.Models.Messages.MsgInUse</th>
                    <th>@CloudStorageLight.SampleWeb.Models.Messages.MsgRole</th>
                    <th>@CloudStorageLight.SampleWeb.Models.Messages.MsgReadAccess</th>
                    <th>@CloudStorageLight.SampleWeb.Models.Messages.MsgWriteAccess</th>
                    <th>@CloudStorageLight.SampleWeb.Models.Messages.MsgModifyAccess</th>
                    <th>@CloudStorageLight.SampleWeb.Models.Messages.MsgControlAccess</th>
                </tr>
                @for (int i = 0; i < Model.AccessTokens.Count; i++)
                {
                    if (Model.AccessTokens[i].Role == "everyone" || Model.AccessTokens[i].Role == "guest")
                    {
                        continue;
                    }
                    <tr>
                        <td>
                            @Html.CheckBox("AccessTokens[" + i.ToString() + "].InUse", true)
                        </td>
                        <td>
                            @Model.AccessTokens[i].Role
                            @Html.Hidden("AccessTokens[" + i.ToString() + "].Role", Model.AccessTokens[i].Role)
                        </td>
                        <td>
                            @Html.CheckBoxFor(x => x.AccessTokens[i].CanRead)
                        </td>
                        <td>
                            @Html.CheckBoxFor(x => x.AccessTokens[i].CanWrite)
                        </td>
                        <td>
                            @Html.CheckBoxFor(x => x.AccessTokens[i].CanModify)
                        </td>
                        <td>
                            @Html.CheckBoxFor(x => x.AccessTokens[i].CanControl)
                        </td>
                    </tr>
                    {
                        idx++;
                    }
                }

                @for (int i = idx; i < idx + 3; i++)
                {
                    <tr>
                        <td></td>
                        <td>
                            @Html.TextBox("AccessTokens[" + i.ToString() + "].Role")
                        </td>
                        <td>
                            @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanRead")
                        </td>
                        <td>
                            @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanWrite")
                        </td>
                        <td>
                            @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanModify")
                        </td>
                        <td>
                            @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanControl")
                        </td>
                    </tr>
                }
             
@{
                int everyoneIdx = idx + 3;
                var eveyone = Model.AccessTokens.FirstOrDefault(x => x.Role == "everyone");
}
                <tr>
                    <td>
                        @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].InUse", eveyone != null)
                    </td>
                    <td>
                        全てのユーザ
                        @Html.Hidden("AccessTokens[" + everyoneIdx.ToString() + "].Role", "everyone")
                    </td>
                    <td>
                        @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanRead", eveyone != null && eveyone.CanRead)
                    </td>
                    <td>
                        @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanWrite", eveyone != null && eveyone.CanWrite)
                    </td>
                    <td>
                        @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanModify", eveyone != null && eveyone.CanModify)
                    </td>
                    <td>
                        @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanControl", eveyone != null && eveyone.CanControl)
                    </td>
                </tr>
                @{
        int guestIdx = everyoneIdx + 1;
        var guest = Model.AccessTokens.FirstOrDefault(x => x.Role == "guest");
                }
                <tr>
                    <td>
                        @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].InUse", guest != null)
                    </td>
                    <td>
                        @CloudStorageLight.SampleWeb.Models.Messages.MsgGuestPublic
                        @Html.Hidden("AccessTokens[" + guestIdx.ToString() + "].Role", "guest")
                    </td>
                    <td>
                        @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].CanRead", guest != null && guest.CanRead)
                    </td>
                    <td>
                        @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].CanWrite", guest != null && guest.CanWrite)
                    </td>
                    <td>
                        @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].CanModify", guest != null && guest.CanModify)
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
            </table>


            @Html.Hidden("id", Model.Path)
            <hr />
        </div>

        <hr />

        <button id="blobItemDetailOkButton" type="button" onclick="CloudStorageLight.StorageController.updateFolder();">@(CloudStorageLight.SampleWeb.Models.Messages.MsgSave)</button>
        <button type="button" onclick="CloudStorageLight.StorageController.closeUpdateFolderDialog();">@(CloudStorageLight.SampleWeb.Models.Messages.MsgCancel)</button>
    }

</div>
